package com.android.yummycookies.model.cookie;

import java.util.ArrayList;

import com.android.yummycookies.util.Validator;

import android.graphics.Bitmap;
import android.graphics.Rect;

public class MultipleCookieSprite extends AnimatedCookie {

	public static final String TAG = MultipleCookieSprite.class.getSimpleName();

	private final int nbSprites;
	private int tempo = 200;
	ArrayList<Rect> animationRects = new ArrayList<Rect>();

	public MultipleCookieSprite(Bitmap bitmap, int nbSprites) {
		super(bitmap);

		Validator.checkIsPositive(TAG, "number of sprites animation", nbSprites);

		this.nbSprites = nbSprites;
		createAnimationRects();
	}

	public MultipleCookieSprite(Bitmap bitmap, int nbSprites, int tempo) {
		this(bitmap, nbSprites);
		this.tempo = tempo;
	}

	private void createAnimationRects() {
		int spriteHeight = getBitmap().getHeight();
		int spriteWidth = getBitmap().getWidth() / nbSprites;

		for (int i = 0; i < nbSprites; i++) {
			Rect r = new Rect(i * spriteWidth, 0, (i + 1) * spriteWidth,
					spriteHeight);
			animationRects.add(r);
		}
	}

	@Override
	public void update() {
		// TODO methode d'animation timer

	}

	public int getNbSprites() {
		return nbSprites;
	}

	public int getTempo() {
		return tempo;
	}

	public void setTempo(int tempo) {
		this.tempo = tempo;
	}

}
